<?php
/**
* The help library.
*
* Copyright (c) 2009 James Gauld <james@jamesgauld.net>
* This file is part of Scribble.
* @license http://www.scribblecms.co.uk/license.txt
*
* @package Scribble
*/
use Buan\Config;
class HelpController extends ScribbleAdminController {

	/**
	* Display the requested help page.
	*
	* @param array Action parameters (argument #1 is the requested help topic)
	* @return View
	*/
	public function index($params) {

		// Init
		$view = new ScribbleAdminView();
		if(!$this->init($view)) {
			return $view;
		}
		$view->setSource(Config::get('ext.Scribble.dir.views').'/scribble/help/index.tpl.php');

		return $view;
	}

	public function unknown($params, $action) {

		// Init
		$view = new ScribbleAdminView();
		if(!$this->init($view)) {
			return $view;
		}

		// Determine if the requested page exists
		$src = Config::get('ext.Scribble.dir.views')."/scribble/help/{$action}";
		while($p = array_shift($params)) {
			$src .= "/{$p}";
		}
		if(!file_exists("{$src}.tpl.php")) {
			return $this->error404();
		}
		$view->setSource("{$src}.tpl.php");

		// Add a secondary view, if it exists
		$sSrc = "{$src}.secondary.tpl.php";
		if(file_exists($sSrc)) {
			$sView = new ScribbleAdminView();
			$sView->setSource($sSrc);
			ScribbleAdminView::getGlobalView()->attachViewToSlot($sView, 'secondary');
		}

		// Result
		return $view;
	}
}
?>